package com.epoch.server.view;


import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;


public class ServerFrame extends JFrame implements ActionListener {
    //主分页板
    public JTabbedPane tpServer;
    //服务器面板
    JPanel panServer,panServerInfor;
    JLabel labServerName,labIP,labPort;
    JTextField txtServerName,txtIP,txtPort;
    JButton butStopit;

    public ServerFrame(){
        //设置窗体基本属性
        setTitle("Echo--聊天服务器");
        setSize(400,250);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setResizable(false);
        setVisible(true);

        Dimension scr = Toolkit.getDefaultToolkit().getScreenSize();// 在屏幕居中显示
        //Toolkit是抽象类，不能使用new Toolkit() 创建实例化对象，
        // 须通过静态方法getDefaultToolkit() 来获取Toolkit对象
        Dimension fra = this.getSize();

        this.setLocation((scr.width - fra.width) / 2, (scr.height - fra.height) / 2);
        this.setIconImage((new ImageIcon(this.getClass().getResource("/imgs/login_title.png"))).getImage());


        //设置服务器信息
        panServerInfor = new JPanel(new GridLayout(14,1));
        panServerInfor.setBackground(new Color(180,220,230));
        panServerInfor.setFont(new Font("宋体",0,12));
        panServerInfor.setBorder(BorderFactory.createCompoundBorder(
                BorderFactory.createTitledBorder(""),BorderFactory.createEmptyBorder(1,1,1,1)
        ));

        labServerName = new JLabel("服 务 器 名 称:");
        labServerName.setForeground(Color.BLACK);
        labServerName.setFont(new Font("宋体", 0, 12));
        txtServerName = new JTextField("Echo——Chat",10);
        txtServerName.setBackground(Color.WHITE);
        txtServerName.setFont(new Font("宋体", 0, 12));
        txtServerName.setEditable(false);
        
        labIP = new JLabel("服 务 器 IP:");
        labIP.setForeground(Color.BLACK);
        labIP.setFont(new Font("宋体", 0, 12));
        txtIP = new JTextField("127.0.0.1",10);
        txtIP.setBackground(Color.white);
        txtIP.setFont(new Font("宋体", 0, 12));
        txtIP.setEditable(false);

        labPort = new JLabel("服 务 器 端 口:");
        labPort.setForeground(Color.BLACK);
        labPort.setFont(new Font("宋体", 0, 12));
        txtPort = new JTextField("9999",10);
        txtPort.setBackground(Color.white);
        txtPort.setFont(new Font("宋体", 0, 12));
        txtPort.setEditable(false);


        panServerInfor.setBounds(0,0,120,250);
        panServerInfor.add(labServerName);
        panServerInfor.add(txtServerName);
        panServerInfor.add(labIP);
        panServerInfor.add(txtIP);
        panServerInfor.add(labPort);
        panServerInfor.add(txtPort);

        //服务器面板
        panServer = new JPanel();
        panServer.setLayout(null);
        panServer.setBackground(new Color(150,200,230));
        panServer.add(panServerInfor);

        //按钮键
        butStopit = new JButton("关 闭 服 务 器");
        butStopit.setFocusPainted(false);
        butStopit.setBounds(170,75,170,30);
        butStopit.setBackground(new Color(255,50,50));
        panServer.add(butStopit);
        butStopit.addActionListener(this);

        //主标签面板
        tpServer = new JTabbedPane(JTabbedPane.TOP);
        tpServer.setBackground(Color.CYAN);
        tpServer.setFont(new Font("宋体",0,15));
        tpServer.add("服务器管理",panServer);
        this.add(tpServer);

    }

    @Override
    public void actionPerformed(ActionEvent e) {
        if(e.getSource() == butStopit){
            this.dispose();
            System.exit(0);
        }
    }
}